import 'package:flutter/material.dart';

class AnimatedPaddingDemo extends StatefulWidget {
  @override
  _AnimatedPaddingDemoState createState() => _AnimatedPaddingDemoState();
}

class _AnimatedPaddingDemoState extends State<AnimatedPaddingDemo> {
  var _padding = 0.0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("AnimatedOpacityDemo")),
      body: AnimatedPadding(
        padding: EdgeInsets.symmetric(horizontal: _padding),
        duration: Duration(seconds: 2),
        child: Container(color: Colors.red),
      ),
      floatingActionButton: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          FloatingActionButton(
            //开始动画
            onPressed: () {
              setState(() {
                if (_padding == 50) {
                  _padding = 0;
                } else {
                  _padding = 50;
                }
              });
            },
            child: Icon(Icons.add),
          ),
        ],
      ),
    );
  }
}
